package com.mask.im.business.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mask.im.business.model.entity.SysExceptionLogEntity;
import com.mask.im.business.mapper.ExceptionLogMapper;
import com.mask.im.business.model.dto.ExceptionLogDTO;
import com.mask.im.business.model.vo.ConditionVO;
import com.mask.im.business.common.model.PageResult;
import com.mask.im.business.service.SysExceptionLogService;
import com.mask.im.business.common.util.BeanCopy;
import com.mask.im.business.common.util.PageUtil;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysExceptionLogServiceImpl extends ServiceImpl<ExceptionLogMapper, SysExceptionLogEntity> implements SysExceptionLogService {

    @Override
    public PageResult<ExceptionLogDTO> listExceptionLogs(ConditionVO conditionVO) {
        Page<SysExceptionLogEntity> page = new Page<>(PageUtil.getLimitPage(), PageUtil.getSize());
        Page<SysExceptionLogEntity> exceptionLogPage = this.page(page, new LambdaQueryWrapper<SysExceptionLogEntity>()
                .like(StringUtils.isNotBlank(conditionVO.getKeywords()), SysExceptionLogEntity::getOptDesc, conditionVO.getKeywords())
                .orderByDesc(SysExceptionLogEntity::getId));
        List<ExceptionLogDTO> exceptionLogDTOs = BeanCopy.listCopy(exceptionLogPage.getRecords(), ExceptionLogDTO.class);
        return PageResult.<ExceptionLogDTO>builder().data(exceptionLogDTOs).total((int) exceptionLogPage.getTotal()).build();
    }

}
